<?php
/**
 * Created by PhpStorm.
 * User: shuai
 * Date: 2016/7/27
 * Time: 20:59
 * 会员中心
 */
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin', 'admin', 0);
pc_base::load_app_class('foreground');
pc_base::load_sys_class('format', '', 0);
pc_base::load_sys_class('form', '', 0);
class member_enter extends admin {

    public function __construct() {
        parent::__construct();
        $this->shuafen_buy_money_conf = pc_base::load_model('shuafen_buy_money_conf_model');
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $this->shuafen_buy_record = pc_base::load_model('shuafen_buy_record_model');
        $this->member = pc_base::load_model('member_model');
    }


    public function buy_money_conf(){
        $page = max(intval($_GET['page']), 1);
        $infos = $this->shuafen_buy_money_conf->listinfo('', '', $page);
        $pages = $this->shuafen_buy_money_conf->pages;
        include $this->admin_tpl('buy_money_conf/money_list');
    }

    public function add_buy_money_conf(){
        if (isset($_POST['dosubmit'])) {
            if($_POST['id']){
                $this->shuafen_buy_money_conf->update(array('money'=>$_POST['money']), array('id'=>$_POST['id']));
                showmessage(L('修改成功'), 'index.php?m=shuafen&c=member_enter&a=buy_money_conf');
            }else{
                $info['create_time'] = SYS_TIME;
                $id = $this->shuafen_buy_money_conf->insert($info, true);
                if ($id) {
                    showmessage(L('添加成功'), 'index.php?m=shuafen&c=member_enter&a=buy_money_conf');
                }else {
                    showmessage(L('operation_failure'), 'index.php?m=shuafen&c=member_enter&a=buy_money_conf');
                }
            }
        }else{
            $action = $_GET['action'];
            if($action){
                $id = $_GET['id'];
                $money_conf = $this->shuafen_buy_money_conf->get_one(array('id'=>$id));
            }
        }
        include $this->admin_tpl('buy_money_conf/add_money');
    }

    public function transfer_money_conf(){
        if (isset($_POST['dosubmit'])) {
            $data['transfer_money_conf'] = $_POST['transfer_money_conf'];
            $this->shuafen_download_times->update($data, array('id'=>$_POST['id']));
            showmessage(L('修改成功'), 'index.php?m=shuafen&c=member_enter&a=transfer_money_conf');
        }else{
            $num = $this->shuafen_download_times->get_one();
        }
        include $this->admin_tpl('download/transfer_money_conf');
    }

    public function member_buy_record(){
        $page = max(intval($_GET['page']), 1);
        $infos = $this->shuafen_buy_record->listinfo('','time desc , id desc ', $page);
        $pages = $this->shuafen_buy_record->pages;
        include $this->admin_tpl('member/buy_record');
    }

    public function free_data(){
        $page = max(intval($_GET['page']), 1);
        $where = 'trash = 0 and add_times>0';
        if(isset($_GET['username']) && trim($_GET['username'])){
            $tel=$_GET['username'];
            $where .= " AND username = ".trim($_GET['username']);
        }
        $infos = $this->member->listinfo($where,'free_top desc , free_top_time desc , userid desc', $page);
        $pages = $this->member->pages;
        $top = array('0'=>'否','1'=>'是');
        $sex = array('0'=>'男','1'=>'女');
        include $this->admin_tpl('member/free_data');
    }

    public function top_free_data(){
        $userid = $_GET['userid'];
        if($userid){
            $action = $_GET['action'];
            if($action){
                $data['free_top'] = 0;
                $data['free_top_time'] = 0;
            }else{
                $data['free_top'] = 1;
                $data['free_top_time'] = SYS_TIME;
            }
            $this->member->update($data,array('userid'=>$userid));
            showmessage(L('操作成功'), 'index.php?m=shuafen&c=member_enter&a=free_data');
        }
    }

    public function free_down_num(){
        if (isset($_POST['dosubmit'])) {
            $data['free_down_times'] = $_POST['free_down_times'];
            $this->shuafen_download_times->update($data, array('id'=>$_POST['id']));
            showmessage(L('修改成功'), 'index.php?m=shuafen&c=member_enter&a=free_down_num');
        }else{
            $num = $this->shuafen_download_times->get_one();
        }
        include $this->admin_tpl('download/free_data_down_num');
    }



    public function register_member(){
        $page = max(intval($_GET['page']), 1);
        $pagesize = 20;
        $where = 'trash = 0';
        if(isset($_GET['username']) && trim($_GET['username'])){
            $tel=$_GET['username'];
            $where .= " AND username = ".trim($_GET['username']);
        }
        if(isset($_GET['type']) && $_GET['type']){
            $type = $_GET['type'];
            if($type == 'vip'){
                $where .= " AND vip = 'Y'";
            }
            if($type == 'svip'){
                $where .= " AND svip = 'Y'";
            }
        }
        $infos = $this->member->listinfo($where,'userid desc', $page,$pagesize);
        $pages = $this->member->pages;
        $top = array('0'=>'否','1'=>'是');
        $sex = array('0'=>'男','1'=>'女');
        $is_vip = array('N'=>'否','Y'=>'是');
        $this->type = array(''=>'请选择','vip'=>'vip用户','svip'=>'svip用户');
        include $this->admin_tpl('member/register_member');
    }
}
